package eg.com.itiga.repository.factory;

import java.util.ResourceBundle;

import eg.com.itiga.repository.base.BaseDao;
import eg.com.itiga.repository.company.CompanyDao;
import eg.com.itiga.repository.company.RegCompanyDao;
import eg.com.itiga.repository.exception.DataException;

import eg.com.itiga.repository.itian.BranchDao;

import eg.com.itiga.repository.itian.ItianDao;
import eg.com.itiga.repository.role.RoleDao;
import eg.com.itiga.repository.user.UserDao;


public class RepositoryFactory {
	public static BaseDao createBaseDao() throws DataException {
		ResourceBundle resourceBundle = ResourceBundle.getBundle("RepositoryFactory");
		
		String baseDaoFullyQualifiedName = resourceBundle.getString("BaseDao");
		
		try {
			return (BaseDao)Class.forName(baseDaoFullyQualifiedName).newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
			throw new DataException("Factory Failed");
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new DataException("Factory Failed");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new DataException("Factory Failed");
		}
		
	}

	public static BranchDao createBranchDao() throws DataException {
		ResourceBundle resourceBundle = ResourceBundle.getBundle("RepositoryFactory");
		
		String branchDaoFullyQualifiedName = resourceBundle.getString("BranchDao");
		
		try {
			return (BranchDao)Class.forName(branchDaoFullyQualifiedName).newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
			throw new DataException("Factory Failed");
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new DataException("Factory Failed");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new DataException("Factory Failed");
		}
		
	}

	
	public static RoleDao createRoleDao() throws DataException {
		ResourceBundle resourceBundle = ResourceBundle.getBundle("RepositoryFactory");
		
		String roleDaoFullyQualifiedName = resourceBundle.getString("RoleDao");
		
		try {
			return (RoleDao)Class.forName(roleDaoFullyQualifiedName).newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
			throw new DataException("Factory Failed");
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new DataException("Factory Failed");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new DataException("Factory Failed");
		}
		
	}
	
	public static UserDao createUserDao() throws DataException {
		ResourceBundle resourceBundle = ResourceBundle.getBundle("RepositoryFactory");
		
		String userDaoFullyQualifiedName = resourceBundle.getString("UserDao");
		
		try {
			return (UserDao)Class.forName(userDaoFullyQualifiedName).newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
			throw new DataException("Factory Failed");
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new DataException("Factory Failed");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new DataException("Factory Failed");
		}		
	}
	
	public static RegCompanyDao createRegCompanyDao() throws DataException 
	{
		ResourceBundle resourceBundle = ResourceBundle.getBundle("RepositoryFactory");
		
		String baseDaoFullyQualifiedName = resourceBundle.getString("RegCompanyDao");
		
		try {
			return (RegCompanyDao)Class.forName(baseDaoFullyQualifiedName).newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
			throw new DataException("Factory Failed");
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new DataException("Factory Failed");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new DataException("Factory Failed");
		}		
	}

	public static ItianDao createItianDao() throws DataException {
        ResourceBundle resourceBundle = ResourceBundle.getBundle("RepositoryFactory");
       
        String itianDaoFullyQualifiedName = resourceBundle.getString("ItianDao");
       
        try {
            return (ItianDao)Class.forName(itianDaoFullyQualifiedName).newInstance();
       
        } catch (InstantiationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
           
            throw new DataException("Factory Failed");
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            throw new DataException("Factory Failed");
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            throw new DataException("Factory Failed");
        }
       
    }
    public static CompanyDao createCompanyDao() throws DataException {
        ResourceBundle resourceBundle = ResourceBundle.getBundle("RepositoryFactory");
       
        String companyDaoFullyQualifiedName = resourceBundle.getString("CompanyDao");
       
        try {
            return (CompanyDao)Class.forName(companyDaoFullyQualifiedName).newInstance();
       
        } catch (InstantiationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
           
            throw new DataException("Factory Failed");
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            throw new DataException("Factory Failed");
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            throw new DataException("Factory Failed");
        }
       
    }


}
